
#ifndef   _GPIO_CONFIG_H_
#define   _GPIO_CONFIG_H_
#include "config.h"
#include "customer_config.h"

/*******************************28 pin********************************************
**********************************gpio_config*************************************/
#ifdef AC209_28PIN
	#define SET_MUTE_PORT_DIR()	P2DIR &= ~(BIT(6))  //P0IE &= 0xfe;//P3DIR &= ~0x10//DACCON0|=0x80;
	#define SET_MUTE_PORT_PU() 			P2PU |= BIT(6) ///P3PU |= 0x10//
	#define MUTE_PORT_HIGH()			P26  =1//P34=1//
	#define MUTE_PORT_LOW()			P26  =0//	P34  =0//
      #define play_led_seg_out()  		P2DIR &= ~(BIT(7));P2PU |= BIT(7); //P0DIR &= ~(1<<2);P0PU |= (1<<2) ;P3DIR |= (1<<4);P3PU &=~ (1<<4);P3PD&=~ (1<<4);DACCON0|=0x80;
      #define PLAY_STATUS_PORT 		P27

      #ifdef LINE_IN_DETECT_USE_P27
      #define  aux_detect_in()     P2DIR |= BIT(7);P2PU |= BIT(7);//DACCON0|=0x80; 
      #define  AUX_DETECT_GPIO  P27
      #define  aux_detect_in_off()        P2DIR &= ~BIT(7); //linein check port
      #else
      #define  aux_detect_in()      P0DIR |= BIT(2);P0PU |= BIT(2);
      #define  AUX_DETECT_GPIO  P02
      #define  aux_detect_in_off()        P0DIR &= ~BIT(2); //linein check port
      #endif

	#define   EARPHONE_DETECT_GPIO  P27
	#define   earphone_detect_in()   P2DIR |= 0x80;P2PU &= ~0x80;  //DACCON0|=0x80;

 #ifdef POWER_SAVE_SYSTEM
	#define power_key_detect_in()	P2DIR &=~(1<<7);P2PU |= (1<<7);P27 =1;;P2DIR |= (1<<7);P2PU &= ~(1<<7);//DACCON0|=0x80;
	#define POWER_KEY_PORT			P27//P34=1//
	#define power_ctl(n)  				P2DIR &= ~(1<<6);P2PU |= (1<<6);P26 = n//DACCON0|=0x80;
#endif
	#define iic_data_out_io()    P0DIR &= ~(1<<1);P0PU |= (1<<1)
	#define iic_data_in_io()     P0DIR |= (1<<1);P0PU |= (1<<1)
	#define iic_data_r_io()      P01
	#define iic_data_io(n)       P01 = n
	#define iic_clk_out_io()    P0DIR &= ~(1<<0);P0PU |= (1<<0)
	#define iic_clk_io(n)       P00 = n
    
/*******************************48 pin********************************************
**********************************gpio_config*************************************/
#else

#ifdef MUTE_PORT_USE_P00
#define SET_MUTE_PORT_DIR()	P0DIR &= ~0x01      //P0IE &= 0xfe;//P3DIR &= ~0x10//
#define SET_MUTE_PORT_PU() 			P0PU |= 0x01//P3PU |= 0x10//
	#ifdef  PA_LOW_MUTE//
	#define MUTE_PORT_HIGH()			P00  =0//P34=1//
	#define MUTE_PORT_LOW()			P00  =1//	P34  =0//
	#else
	#define MUTE_PORT_HIGH()			P00  =1//P34=1//
	#define MUTE_PORT_LOW()			P00  =0//	P34  =0//
	#endif
#elif defined(MUTE_PORT_USE_P26)
#define SET_MUTE_PORT_DIR()	       P2DIR &=~(1<<6);   //P0IE &= 0xfe;//P3DIR &= ~0x10//
#define SET_MUTE_PORT_PU() 			P2PU |= (1<<6);//P3PU |= 0x10//
#define MUTE_PORT_HIGH()			P26 =1//P34=1//
#define MUTE_PORT_LOW()			P26 =0//	P34  =0//   
 #elif defined(MUTE_PORT_USE_P25)
#define SET_MUTE_PORT_DIR()	       P2DIR &=~(1<<5);   //P0IE &= 0xfe;//P3DIR &= ~0x10//
#define SET_MUTE_PORT_PU() 			P2PU |= (1<<5);//P3PU |= 0x10//
#define MUTE_PORT_HIGH()			P25 =1//P34=1//
#define MUTE_PORT_LOW()			P25 =0//	P34  =0//   
 #elif defined(MUTE_PORT_USE_P46)
 #define SET_MUTE_PORT_DIR()	P4DIR &=~(1<<6);   
#define SET_MUTE_PORT_PU() 			P4PU |= (1<<6);
#define MUTE_PORT_HIGH()			P4 |=BIT(6);
#define MUTE_PORT_LOW()			P4 &=~(BIT(6));
 #elif defined(MUTE_PORT_USE_P16)
 #define SET_MUTE_PORT_DIR()	P1DIR &=~(1<<6);   //P0IE &= 0xfe;//P3DIR &= ~0x10//
#define SET_MUTE_PORT_PU() 			P1PU |= (1<<6);//P3PU |= 0x10//
#define MUTE_PORT_HIGH()			P16  =1//P34=1//
#define MUTE_PORT_LOW()			P16 =0//	P34  =0//   
#elif defined(MUTE_PORT_USE_P17)
 #define SET_MUTE_PORT_DIR()	P1DIR &=~(1<<7);   //P0IE &= 0xfe;//P3DIR &= ~0x10//
#define SET_MUTE_PORT_PU() 			P1PU |= (1<<7);//P3PU |= 0x10//
#define MUTE_PORT_HIGH()			P17  =1//P34=1//
#define MUTE_PORT_LOW()			P17 =0//	P34  =0//
#elif defined(MUTE_PORT_USE_P01)
#define SET_MUTE_PORT_DIR()	        P0DIR &=~(1<<1);   //P0IE &= 0xfe;//P3DIR &= ~0x10//
#define SET_MUTE_PORT_PU() 			P0PU |= (1<<1);//P3PU |= 0x10//
           #ifdef  PA_LOW_MUTE//
           #define MUTE_PORT_HIGH()			P01 =0//P34=1//
           #define MUTE_PORT_LOW()			P01  =1//	P34  =0//
           #else
           #define MUTE_PORT_HIGH()			P01  =1//P34=1//
           #define MUTE_PORT_LOW()			P01  =0//	P34  =0//
           #endif
#elif defined(MUTE_PORT_USE_P02)
#define SET_MUTE_PORT_DIR()	        P0DIR &=~(1<<2);   //P0IE &= 0xfe;//P3DIR &= ~0x10//
#define SET_MUTE_PORT_PU() 			P0PU |= (1<<2);//P3PU |= 0x10//
           #ifdef  PA_LOW_MUTE//
           #define MUTE_PORT_HIGH()			P02 =0//P34=1//
           #define MUTE_PORT_LOW()			P02  =1//	P34  =0//
           #else
           #define MUTE_PORT_HIGH()			P02  =1//P34=1//
           #define MUTE_PORT_LOW()			P02  =0//	P34  =0//
           #endif
#elif defined(MUTE_PORT_DISABLE)
#define SET_MUTE_PORT_DIR()	      ;//  P0DIR &=~(1<<2);   //P0IE &= 0xfe;//P3DIR &= ~0x10//
#define SET_MUTE_PORT_PU() 			;//P0PU |= (1<<2);//P3PU |= 0x10//
#define MUTE_PORT_HIGH()			;//P02  =1//P34=1//
#define MUTE_PORT_LOW()			;//P02  =0//	P34  =0//
#else
#define SET_MUTE_PORT_DIR()	        P0DIR &=~(1<<3);   //P0IE &= 0xfe;//P3DIR &= ~0x10//
#define SET_MUTE_PORT_PU() 			P0PU |= (1<<3);//P3PU |= 0x10//
    #ifdef  PA_LOW_MUTE//
        #define MUTE_PORT_HIGH()			P03  =0//P34=1//
        #define MUTE_PORT_LOW()			P03 =1//	P34  =0//
    #else
        #define MUTE_PORT_HIGH()			P03  =1//P34=1//
        #define MUTE_PORT_LOW()			P03 =0//	P34  =0//
    #endif
#endif

#define AMP_MUTE_PORT_INIT() 	SET_MUTE_PORT_DIR();SET_MUTE_PORT_PU();// P0DIR &= ~BIT(1);P0PU &= ~BIT(1);P0PD &= ~BIT(1)
#define AMP_MUTE_DISABLE() 	 MUTE_PORT_LOW();//P01 = 0
#define AMP_MUTE_ENABLE() 	 MUTE_PORT_HIGH();//P01 = 1


#ifdef POWER_CTL_P04
#define powerdowm_ctl(n)  	 P0DIR &= ~(BIT(4));P0PU |= BIT(4); P04=n;
#elif defined(POWER_CTL_WKUP)
#define powerdowm_ctl(n)  	 WakeUp_IO(n);
#else
#define powerdowm_ctl(n)  	 P0DIR &= ~(BIT(2));P0PU |= BIT(2); P02=n;
#endif

#ifdef JOG_KEY
#if defined(KXXX_ANGFENG)
#define JOG_detect_in() P0DIR |= BIT(2);P0PU |= BIT(2);P2DIR |=BIT(5);P2PU |=BIT(5); 
#define JOG_PORT  ;
#else
#define JOG_detect_in() P0DIR |= 0x14;P0PU |= 0x14; 
#define JOG_PORT  P0
#endif
#endif

#if defined( EARPHONE_PLUGGED_USE_P02)
#define  EARPHONE_DETECT_GPIO  P02
#define  earphone_detect_in()  P0DIR |=BIT(2);P0PU |= BIT(2); 
#elif defined( EARPHONE_PLUGGED_USE_P00)
#define  EARPHONE_DETECT_GPIO  P00
#define  earphone_detect_in()  P0DIR |=BIT(0);P0PU |= BIT(0); 
#elif defined( EARPHONE_PLUGGED_USE_P15)
#define  EARPHONE_DETECT_GPIO  P15
#define  earphone_detect_in()  P1DIR |=BIT(5);P1PU |= BIT(5); 
#elif defined( EARPHONE_PLUGGED_USE_P17)
#define  EARPHONE_DETECT_GPIO  P17
#define  earphone_detect_in()  P1DIR |=BIT(7);P1PU|= BIT(7); 
#elif  defined( EARPHONE_PLUGGED_USE_P03)
#define  EARPHONE_DETECT_GPIO  P03
#define  earphone_detect_in()  P0DIR |=BIT(3);P0PU|= BIT(3); 
#elif  defined( EARPHONE_PLUGGED_USE_P04)
#define  EARPHONE_DETECT_GPIO  P04
#define  earphone_detect_in()  P0DIR |=BIT(4);P0PU|= BIT(4); 
#elif  defined( EARPHONE_PLUGGED_USE_P33)
#define  EARPHONE_DETECT_GPIO  P33
#define  earphone_detect_in()  P3DIR |=BIT(3);P3PU|= BIT(3); 
#elif  defined( EARPHONE_PLUGGED_USE_P26)
#define  EARPHONE_DETECT_GPIO  P26
#define  earphone_detect_in()  P2DIE |= 0xc0;P2DIR |=BIT(6);P2PU|= BIT(6); 
#elif  defined( EARPHONE_PLUGGED_USE_P34)
#define  EARPHONE_DETECT_GPIO  P34
#define  earphone_detect_in()  P3DIR |=BIT(4);P3PU|= BIT(4); 
#elif  defined( EARPHONE_PLUGGED_USE_P46)
//#define  EARPHONE_DETECT_GPIO  P4&BIT(6)
#define  earphone_detect_in()  P4DIR |=BIT(6);P4PU|= BIT(6); 
#else
#define  EARPHONE_DETECT_GPIO  P07
#define  earphone_detect_in()   P0DIR |= 0x80;P0PU|= 0x80; 
#define  earphone_detect_port_low()   P0DIR &= ~0x80;P0PD|= 0x80; EARPHONE_DETECT_GPIO=0;
#endif

#ifdef  USE_GPIO_DETECT_MIC
#ifdef  MIC_IN_DETECT_USE_P34
#define  MIC_IN_DETECT_PORT_IN()    P3DIR |= BIT(4);P3PU |=(BIT(4));//P3PD &=~(BIT(4));P3HD &=~(BIT(4));
#define  MIC_IN_DETECT_PORT       P34
#elif defined(MIC_IN_DETECT_USE_P05)
#define  MIC_IN_DETECT_PORT_IN()    P0DIR |= BIT(5);P0PU |=(BIT(5));//P3PD &=~(BIT(4));P3HD &=~(BIT(4));
#define  MIC_IN_DETECT_PORT       P05
#endif
#endif

#ifndef  DISABLE_DISPLAY_LED
#ifdef  PLAY_STATUS_LED_P17
#define play_led_seg_out()    P1DIR &= ~BIT(7);P1PU |= BIT(7);
#define PLAY_STATUS_PORT   P17
#elif defined(K2225_CW001_MY)
#define play_led_seg_out()    P0DIR &= ~(BIT(1));P0PU |= BIT(1);P1DIR &= ~(BIT(7));P1PU |= BIT(7);
#define PLAY_STATUS_PORT   P01
#define PLAY_STATUS_PORT1   P17
#elif defined(PLAY_STATUS_LED_P14)
#define play_led_seg_out()    P1DIR &= ~(BIT(4));P1PU |= BIT(4);
#define PLAY_STATUS_PORT   P14
#elif defined(PLAY_STATUS_LED_P27)
#define play_led_seg_out()    P2DIR &= ~(BIT(7));P2PU |= BIT(7);
#define PLAY_STATUS_PORT   P27
#elif defined(PLAY_STATUS_LED_P01)
#define play_led_seg_out()    P0DIR &= ~(BIT(1));P0PU |= BIT(1);
#define PLAY_STATUS_PORT   P01
#elif defined(PLAY_STATUS_LED_P37)
#define play_led_seg_out()    P3DIR &= ~(BIT(7)); USB_CON0 = 0x11;
#define PLAY_STATUS_PORT   P37
#elif defined(PLAY_STATUS_LED_P05)
#define play_led_seg_out()    P0DIR &= ~(BIT(5));P0PU |= BIT(5);
#define PLAY_STATUS_PORT   P05
#else
 #if defined(USE_TWO_ADKEY)||defined(AD_KEY_USE_P07)
#error("reduplicate funtion P07!")
 #endif
#define play_led_seg_out()    P0DIR &= ~BIT(7);P0PU |= BIT(7);
#define PLAY_STATUS_PORT   P07
#endif
#endif

#ifdef  LINE_IN_DETECT_USE_P01
#define  aux_detect_in()      P0DIR |= BIT(1);P0PU |= BIT(1);//linein check port
#define  AUX_DETECT_GPIO  P01
#define  aux_detect_in_off()        P0DIR &= ~(BIT(1)); //linein check port
#elif defined(LINE_IN_DETECT_USE_P30)
#define  aux_detect_in()      P3DIR |= BIT(0);P0PU |= BIT(0);//linein check port
#define  AUX_DETECT_GPIO  P30
#define  aux_detect_in_off()        P3DIR &= ~BIT(0); //linein check port
#elif defined(LINE_IN_DETECT_USE_P34)
#define  aux_detect_in()      P3DIR |= BIT(4);P0PU |= BIT(4);//linein check port
#define  AUX_DETECT_GPIO  P34
#define  aux_detect_in_off()        P3DIR &= ~BIT(4); //linein check port
#elif defined(LINE_IN_DETECT_USE_P02)
#define  aux_detect_in()      P0DIR |= BIT(2);P0PU |= BIT(2);//linein check port
#define  AUX_DETECT_GPIO  P02
#define  aux_detect_in_off()        P0DIR &= ~BIT(2); //linein check port
#elif defined(LINE_IN_DETECT_USE_P26)
#define  aux_detect_in()      P2DIR |= BIT(6);P2PU |= BIT(6);
#define  AUX_DETECT_GPIO  P26
#define  aux_detect_in_off()        P2DIR &= ~BIT(6); //linein check port
#elif defined(LINE_IN_DETECT_USE_P05)
#define  aux_detect_in()     CLK_CON2 &= ~BIT(4); P0DIR |= BIT(5);P0PU |= BIT(5);//linein check port
#define  AUX_DETECT_GPIO  P05
#define  aux_detect_in_off()        P0DIR &= ~BIT(5); //linein check port
#elif defined(LINE_IN_DETECT_USE_P36)
#define  aux_detect_in()      P3DIR |= BIT(6);P3PU |= BIT(6);
#define  AUX_DETECT_GPIO  P36
#define  aux_detect_in_off()        P2DIR &= ~BIT(6); //linein check port
#elif defined(LINE_IN_DETECT_USE_P06)
#define  aux_detect_in()      P0DIR |= BIT(6);P0PU |= BIT(6);//linein check port
#define  AUX_DETECT_GPIO  P06
#define  aux_detect_in_off()        P0DIR &= ~BIT(6); //linein check port
#elif defined(LINE_IN_DETECT_USE_P07)
#define  aux_detect_in()      P0DIR |= BIT(7);P0PU |= BIT(7);//linein check port
#define  AUX_DETECT_GPIO  P07
#define  aux_detect_in_off()        P0DIR &= ~BIT(7); //linein check port
#else
#define  aux_detect_in()      P0DIR |= BIT(4);P0PU |= BIT(4);//linein check port
#define  AUX_DETECT_GPIO  P04
#define  aux_detect_in_off()        P0DIR &= ~BIT(4); //linein check port
#endif

#ifdef CHARGR_DET_USER_VPP
#define  charge_detect_in()      WKUPPND &=~ (1<<6); //P0DIR |= BIT(4);P0PU |= BIT(4);//linein check port
#elif defined(CHARGR_DET_USE_P01)
#define  charge_detect_in()       P0DIR |= BIT(1);P0PD|= BIT(1);
#define  charge_status_port       P01
#elif defined(CHARGR_DET_USE_P17)
#define  charge_detect_in()       P1DIR |= BIT(7);P1PD|= BIT(7);//P1PDA|= BIT(7);
#define  charge_status_port       P17
#elif defined(CHARGR_DET_USE_P02)
#define  charge_detect_in()       P0DIR |= BIT(2);P0PD|= BIT(2);
#define  charge_status_port       P02
#elif defined(CHARGR_DET_USE_P07)
#define  charge_detect_in()       P0DIR |= BIT(7);P0PD|= BIT(7);
#define  charge_status_port       P07
#elif defined(CHARGR_DET_USE_P05)
#define  charge_detect_in()       DACCON0|=0x40; P0DIR |= BIT(5);P0PD|= BIT(5);
#define  charge_status_port       P05
#else
#define  charge_detect_in()       P0DIR |= BIT(4);P0PD|= BIT(4);
#define  charge_status_port       P04
#endif


#ifdef I2C_USE_PO2_P03_PORT
#define iic_data_out_io()    P0DIR &= ~(1<<2);P0PU |= (1<<2)
#define iic_data_in_io()     P0DIR |= (1<<2);P0PU |= (1<<2)
#define iic_data_r_io()      P02
#define iic_data_io(n)       P02 = n
#define iic_clk_out_io()    P0DIR &= ~(1<<3);P0PU |= (1<<3)
#define iic_clk_io(n)       P03 = n
#elif defined( SDMMC_IIC_SHARE_IO)
        #define iic_data_out_io()    P2DIR &= ~(1<<2);//P2PU |= (1<<2)
        #define iic_data_in_io()     P2DIR |= (1<<2);P2PU |= (1<<2)
        #define iic_data_r_io()      P22
        #define iic_data_io(n)       P22 = n
        #define iic_clk_out_io()    P2DIR &= ~(1<<0);//P2PU |= (1<<0)
        #define iic_clk_io(n)       P20 = n
 #elif defined(I2C_USE_P00_DATA_P01_CLK_PORT)
#define iic_data_out_io()    P0DIR &= ~(1<<0);P0PU |= (1<<0)
#define iic_data_in_io()     P0DIR |= (1<<0);P0PU |= (1<<0)
#define iic_data_r_io()      P00
#define iic_data_io(n)       P00 = n
#define iic_clk_out_io()    P0DIR &= ~(1<<1);P0PU |= (1<<1)
#define iic_clk_io(n)       P01= n
#elif defined(I2C_USE_P02_DATA_P01_CLK_PORT)
#define iic_data_out_io()    P0DIR &= ~(1<<2);P0PU |= (1<<2)
#define iic_data_in_io()     P0DIR |= (1<<2);P0PU |= (1<<2)
#define iic_data_r_io()      P02
#define iic_data_io(n)       P02 = n
#define iic_clk_out_io()    P0DIR &= ~(1<<1);P0PU |= (1<<1)
#define iic_clk_io(n)       P01= n
#else
#define iic_data_out_io()    P0DIR &= ~(1<<1);P0PU |= (1<<1)
#define iic_data_in_io()     P0DIR |= (1<<1);P0PU |= (1<<1)
#define iic_data_r_io()      P01
#define iic_data_io(n)       P01 = n
#define iic_clk_out_io()    P0DIR &= ~(1<<0);P0PU |= (1<<0)
#define iic_clk_io(n)       P00 = n
#endif

#endif

#ifdef  USE_GPIO_COTR_BUL_V
#if defined(Blue_V_CON_OUT_P34)
#define Blue_v_cot_out()     P3DIR &= ~(BIT(4));P3PU |= BIT(4);
#define Blue_V_CON_OUT_PORT  P34
#elif defined(Blue_V_CON_OUT_P23)
#define Blue_v_cot_out()     P2DIR &= ~(BIT(3));P2PU |= BIT(3);
#define Blue_V_CON_OUT_PORT  P23
#else
#define Blue_v_cot_out()     P0DIR &= ~(BIT(4));P0PU |= BIT(4);
#define Blue_V_CON_OUT_PORT  P04
#endif
#endif


#ifdef USE_IO_CONT_BULE
    #if defined(K2205_AC90_YJH)||defined(K2249_AC90_FUMAN)||defined(K2251_AC90_FUMAN)
    #define Blue_key_out()     P3DIR &= ~(BIT(1)|BIT(2)|BIT(3));P3PU |= BIT(1)|BIT(2)|BIT(3);
    #define BLUE_PLAY_KEY_PORT   P33
    #define BLUE_NEXT_KEY_PORT   P31
    #define BLUE_PREV_KEY_PORT   P32
    #define  BLUE_key_off()   Blue_key_out();P33 = 1;P31 = 1;P32 = 1;
    
    #elif defined(K2202_AC94_YJH)
    #define Blue_key_out()     P0DIR &= ~(BIT(0)|BIT(1)|BIT(5));P0PU |= BIT(0)|BIT(1)|BIT(5);
    #define BLUE_PLAY_KEY_PORT   P05
    #define BLUE_NEXT_KEY_PORT   P01
    #define BLUE_PREV_KEY_PORT   P00
    #define  BLUE_key_off()  Blue_key_out();P05 = 0;P31 = 1;P32 = 1;
    
    #elif defined(K1296_LS)
    #define Blue_key_out()     P0DIR &= ~(BIT(0)|BIT(1));P0PU |= BIT(0)|BIT(1); P0DIR &=~ (BIT(5));P0PU |= BIT(5);
    #define BLUE_PLAY_KEY_PORT      P05
    #define BLUE_NEXT_KEY_PORT      P00
    #define BLUE_PREV_KEY_PORT      P01
    #define  BLUE_key_off()  Blue_key_out();P05 = 0;P00 = 1;P01 = 1;
	#elif defined(K886_KEY_MUSIC_LS)
	#define Blue_key_out()     P0DIR &= ~(BIT(4)|BIT(7));P0PU |= BIT(4)|BIT(7); P3DIR &=~ (BIT(5));P3PU |= BIT(5);
    #define BLUE_PLAY_KEY_PORT      P07//P35
    #define BLUE_NEXT_KEY_PORT      P35
    #define BLUE_PREV_KEY_PORT      P04
    #define  BLUE_key_off()  Blue_key_out();P35 = 0;P04 = 1;P35 = 1;
    #elif defined(K1296_1268_LS)
	#define Blue_key_out()     P0DIR &= ~(BIT(4)|BIT(3));P0PU |= BIT(4)|BIT(3); P3DIR &=~ (BIT(5));P3PU |= BIT(5);
    #define BLUE_PLAY_KEY_PORT      P03
    #define BLUE_NEXT_KEY_PORT      P35
    #define BLUE_PREV_KEY_PORT      P04
    #define  BLUE_key_off()  Blue_key_out();P35 = 0;P04 = 0;P03 = 0;
    #elif defined(K968_BT_LS)||defined(K886_VOICE_LS)
    #define Blue_key_out()     P0DIR &= ~(BIT(2)|BIT(4));P0PU |= BIT(2)|BIT(4); \
                                                P0DIR &=~ (BIT(7));P0PU |= BIT(7);
    #define BLUE_PLAY_KEY_PORT      P07
    #define BLUE_NEXT_KEY_PORT      P04
    #define BLUE_PREV_KEY_PORT      P02
    #define BLUE_key_off()  Blue_key_out();P07 = 1;P02 = 1;P04 = 1;
    #else
    
    #define Blue_key_out()     P1DIR &= ~(BIT(5)|BIT(6)|BIT(7));P1PU |= BIT(5)|BIT(6)|BIT(7);
    #define BLUE_PLAY_KEY_PORT   P17
    #define BLUE_NEXT_KEY_PORT   P16
    #define BLUE_PREV_KEY_PORT   P15
    
    #define  BLUE_key_off()  Blue_key_out();P17 = 0;P16 = 0;P15 = 0;
    #endif

    #if defined(K968_BT_LS)||defined(K886_KEY_MUSIC_LS)
    #define  bl_long_tim   100
    #define  bl_tim     17
    #else
    #define  bl_long_tim   40
    #define  bl_tim     25
    #endif
#endif


#ifdef  SUPPORT_CD4052
#define  CD4052_INT()     P0DIR &= ~(1<<4);P0PU |= BIT(4); P3DIR &= ~(1<<4);P3PU |= BIT(4);

#define  CD4052A_L()       P0DIR &= ~(1<<4);P0PU |= BIT(4);P04=0;
#define  CD4052A_H()       P0DIR &= ~(1<<4);P0PU |= BIT(4);P04=1;
#define  CD4052B_L()       P3DIR &= ~(1<<4);P3PU |= BIT(4);P34=0;
#define  CD4052B_H()       P3DIR &= ~(1<<4);P3PU |= BIT(4);P34=1;

#define  SELECT_N1()   CD4052A_L();CD4052B_L();
#define  SELECT_N2()   CD4052A_L();CD4052B_H();
#define  SELECT_N3()   CD4052A_H();CD4052B_H();
#define  SELECT_N4()   CD4052A_H();CD4052B_L();
#endif

#ifdef  USE_IO_SWITCH_AP_MOD
#ifdef MP3_FM_SWITCH_PORT_P07
#define  MP3_FM_SWITCH_PORT_OUT()    P0DIR &= ~(BIT(7));P0PU |= BIT(7);
#define MP3_FM_SWITCH_PORT  P07
#elif   defined(MP3_FM_SWITCH_PORT_P06)
#define  MP3_FM_SWITCH_PORT_OUT()    P0DIR &= ~(BIT(6));P0PU |= BIT(6);
#define MP3_FM_SWITCH_PORT  P06
#elif   defined(MP3_FM_SWITCH_PORT_P17)
#define  MP3_FM_SWITCH_PORT_OUT()    P1DIR &= ~(BIT(7));P1PU |= BIT(7);
#define MP3_FM_SWITCH_PORT  P17
#elif   defined(MP3_FM_SWITCH_PORT_P04)
#define  MP3_FM_SWITCH_PORT_OUT()    P0DIR &= ~(BIT(4));P0PU |= BIT(4);
#define MP3_FM_SWITCH_PORT  P04
#endif
#endif


#ifdef IPHONE_DETECT
#if defined(IPHONE_DETECT_USE_P04)
#define  IPhone_detect_in()     P04=1;P0DIR |= BIT(4);/*P0PU|=(BIT(4));*/P0PD|=(BIT(4));//linein check portP1DIR |= BIT(7);P1PDA|=(BIT(7));P1PU&=~(BIT(7));//linein check port
#define  IPHONE_DETECT_GPIO  P04
#elif defined(IPHONE_DETECT_USE_P03)
#define  IPhone_detect_in()     P03=1;P0DIR |= BIT(3);/*P0PU|=(BIT(4));*/P0PD|=(BIT(3));//linein check portP1DIR |= BIT(7);P1PDA|=(BIT(7));P1PU&=~(BIT(7));//linein check port
#define  IPHONE_DETECT_GPIO  P03
#elif defined(IPHONE_DETECT_USE_P32)
#define  IPhone_detect_in()    P32=0;P3DIR |= BIT(2);P3PD|=(BIT(2));
#define  IPHONE_DETECT_GPIO  P32
#elif defined(IPHONE_DETECT_USE_P30)
#define  IPhone_detect_in()    P30=0;P3DIR |= BIT(0);P3PD|=(BIT(0));
#define  IPHONE_DETECT_GPIO  P30
#elif defined(IPHONE_DETECT_USE_P25)
#define  IPhone_detect_in()    DACCON0|=0x40; P25=1;P2DIR |= BIT(5);
#define  IPHONE_DETECT_GPIO  P25
#elif  defined(IPHONE_DETECT_USE_P05)
#define  IPhone_detect_in()     P05=0;P0DIR |= BIT(5);P0PD|=(BIT(5));P0PU&=~(BIT(5));//linein check portP1DIR |= BIT(7);P1PDA|=(BIT(7));P1PU&=~(BIT(7));//linein check port
#define  IPHONE_DETECT_GPIO  P05
#else
#define  IPhone_detect_in()     P06=1;P0DIR |= BIT(6);P0PU|=(BIT(6));P0PD&=~(BIT(6));//linein check portP1DIR |= BIT(7);P1PDA|=(BIT(7));P1PU&=~(BIT(7));//linein check port
#define  IPHONE_DETECT_GPIO  P06
#endif
#endif

#ifdef  P23_HI_ZU
#define  GPIO_P23_OFF()            P2DIR |=BIT(3);P2PU &=~(BIT(3));P2PD &=~(BIT(3));
#endif

#if (LED_TYPE==LED_7TUOYUAN_CHARGE_LED||LED_TYPE==LED_7PALY_PAUSE_LED||LED_TYPE==LED_7PALY_AUX_CHAGE)
    #if defined(K2201_D68_BNX)||defined(USE_24PIN_CHIP_7PIN_LED)
    #define led_com_out()       ;//P3DIR &= ~0x1F; P3PU = 0x1f;//P3PD |= 0x1f; PWM4_CON = 0xcf
    #define led_seg_out()        ;
    #define led_off()                    P2DIR |= BIT(6)|BIT(7);P2PU &= ~(BIT(6)|BIT(7));P2PD &= ~(BIT(6)|BIT(7)); \
                                                  P1DIR |= BIT(6)|BIT(7);P1PU &= ~(BIT(6)|BIT(7));P1PD &= ~(BIT(6)|BIT(7)); \
                                                 CLK_CON2 &= ~BIT(4);P0DIR |= BIT(0)|BIT(1)|BIT(5);P0PU &= ~(BIT(0)|BIT(1)|BIT(5));P0PD &= ~(BIT(0)|BIT(1)|BIT(5)); 
                                                  
    #define  LED_BIT_HZ(n)        ;
    #define  LED_ALL_HZ()           led_off();
     
    #define  LED_BIT_OUT_H(n);
    #define  LED_BIT_OUT_L(n);
    #else
    #define led_com_out()       ;//P3DIR &= ~0x1F; P3PU = 0x1f;//P3PD |= 0x1f; PWM4_CON = 0xcf
    #define led_seg_out()        ;
    #define led_off()                    P1DIR |= 0x7F;P1PU &= ~0x7F;P1PD &= ~0x7F;
    #define  LED_BIT_HZ(n)         P1DIR |= BIT(n);P1PU&=~(BIT(n));P1PD&=~(BIT(n));
    #define  LED_ALL_HZ()          P1DIR |= 0x7F;P1PU &= ~0x7F;P1PD &= ~0x7F;
    #define  LED_BIT_OUT_H(n)   P1DIR &=~(BIT(n));P1HD |= BIT(n);P1 |=1<<n;//P1PU |= BIT(n);P1PD |= BIT(n);P1HD |= BIT(n);
    #define  LED_BIT_OUT_L(n)   P1DIR &=~(BIT(n));P1HD |= BIT(n);P1 &=~(1<<n);//
    #endif
#elif (LED_TYPE==LED_4X8888_JLH)
    #define led_com_out() P3DIR &= ~0x0F; P3HD = 0x0f,P3PD |= 0x0f; PWM4_CON = 0xcf
    #define led_seg_out() P1DIR &= ~0xFF;
    #define led_off()         P1DIR |= 0xFF;P1PU &= ~0xFF;P1PD &= ~0xFF;
#else
    #ifdef  LED_COM5_P17
    #define led_com_out() P3DIR &= ~0x0F; P3HD |= 0x0f;P3PD |= 0x0f; P1DIR &= ~BIT(7);P1HD|=BIT(7);P1PD|=BIT(7);//P3PU
    #define led_seg_out() P1DIR &= ~0x7F
    #define led_off()         P1DIR |= 0x7F;P1PU &= ~0x7F;P1PD &= ~0x7F;
    #else
		#if defined(FLASH_MUSIC_EN)
			#define led_com_out() P3DIR &= ~0x1F; P3HD = 0x1e,P3PD |= 0x1e;P1DIR &= ~(BIT(4)); P1HD |= BIT(4),P1PD |= BIT(4);
			#define led_seg_out() P1DIR &= ~0x0F;P0DIR &=~(BIT(0)|BIT(1));P4DIR &=~(BIT(4));
			#define led_off()         P1DIR |= 0x0F;P1PU &= ~0x0F;P1PD &= ~0x0F;P0DIR |=(BIT(0)|BIT(1)); \
								P0PU &= ~0x03;P0PD &= ~0x03;P4PU &= ~(BIT(4));P4PD &= ~(BIT(4));
		#else
    		#if defined(K4131_JIAMEId)
			#define led_com_out() P3DIR &= ~0x1F; P3PU |=0x1f;  PWM4_CON = 0xcf  //P3HD = 0x1f,P3PD |= 0x1f;
        	#else
			#define led_com_out() P3DIR &= ~0x1F; P3HD = 0x1f,P3PD |= 0x1f; PWM4_CON = 0xcf
      		#endif
			#if defined(P05_FOR_SET7)
				#define led_seg_out() P1DIR &= ~0x3F;P0DIR &=~(BIT(5));
				#define led_off()         P1DIR |= 0x7F;P1PU &= ~0x7F;P1PD &= ~0x7F; \
				        CLK_CON2 &= ~BIT(4);P0DIR |=BIT(5);P0PU &=~(BIT(5));P0PD &=~(BIT(5))
			#elif defined(K1096n_YJH)
  				#define led_seg_out() P1DIR &= ~0x7F;P1HD |=0x7F;
				#define led_off()         P1DIR |= 0x7F;P1PU &= ~0x7F;P1PD &= ~0x7F;
			#else
				#define led_seg_out() P1DIR &= ~0x7F
				#define led_off()         P1DIR |= 0x7F;P1PU &= ~0x7F;P1PD &= ~0x7F;
			#endif
		#endif
    #endif
#endif

#ifdef  AUDIO_LED_FLASH
    #if(LED_TYPE==LED_7PALY_PAUSE_LED||LED_TYPE==LED_7TUOYUAN_CHARGE_LED||LED_TYPE==LED_7PALY_AUX_CHAGE)    
        #if defined(KXXX_A27_SES)
        #define audio_led_out()    P3DIR &= ~0x0f; P3PU = 0x0f; 
        #define audio_led_off()    P3DIR |=0x0f;
        #else
        #define audio_led_out()    P3DIR &= ~0x1F; P3PU = 0x1f; \
                                                    P0DIR &=~(BIT(2));P0PU |=BIT(2);P1DIR &=~(BIT(7));P1PU |=BIT(7);
        #define audio_led_off()    P3DIR |=0x1f;P0DIR |=(BIT(2));P1DIR |=(BIT(7));
        #endif
    #elif defined(K16_J16_LS)
     #define audio_led_out()   P0DIR &=~(BIT(0)|BIT(1)|BIT(7));P0HD |=(BIT(0)|BIT(1)|BIT(7));P4DIR &=~(BIT(6));P4PU |=BIT(6);P3DIR &= ~(BIT(7)); USB_CON0 = 0x11;
    #define audio_led_off()    P0DIR |=(BIT(0)|BIT(1)|BIT(7));P0PU |=(BIT(0)|BIT(1)|BIT(7));P4DIR |=(BIT(6));P4PU |=BIT(6);   
    #else
   #define  audio_led_out() ;      
   #define  audio_led_off() ;      
    #endif
#endif

#ifdef  AUDIO_LED_USE_COM6
#if  defined(LED_ROLLING_COM6_P17)
#define   LED_COM6_init()        P1DIR &= ~(1<<7);P1PU |= BIT(7);
#define  LED_COM6  P17
#elif  defined(LED_ROLLING_COM6_P34)
#define   LED_COM6_init()        P3DIR &= ~(1<<4);P3PU |= BIT(4);
#define  LED_COM6  P34
#else
#define   LED_COM6_init()        P0DIR &= ~(1<<2);P0PU |= BIT(2);
#define  LED_COM6  P02
#endif
#endif


#ifdef  FLASH_MUSIC_EN
#define LED_COM1   P14
#else
#define LED_COM1   P30
#endif
#define LED_COM2   P31
#define LED_COM3   P32
#define LED_COM4   P33
#ifdef  LED_COM5_P17
#define LED_COM5   P17
#else
#define LED_COM5   P34
#endif

#define LED_SEG0   P10
#define LED_SEG1   P11
#define LED_SEG2   P12
#define LED_SEG3   P13
#define LED_SEG4   P14
#define LED_SEG5   P15
#ifdef P05_FOR_SET7
#define LED_SEG6   P05
#else
#define LED_SEG6   P16
#endif
#if(LED_TYPE==LED_4X8888_JLH)
#define LED_SEG7   P17
#endif

#ifdef  GPIO_DISPLAY_BAT
#define BAT_DISPLAY_PORT_OUT()    P3DIR &= ~(BIT(1)|BIT(2)|BIT(3));P0PU |= (BIT(1)|BIT(2)|BIT(3));P0DIR &=~(BIT(4));P0PU |= BIT(4);
#define BAT_LED1_PORT  P33
#define BAT_LED2_PORT  P32
#define BAT_LED3_PORT  P31
#define BAT_LED4_PORT  P04
#endif

#define LED_COM     P3
#define LED_SEG     P1
#define LED_COM_MASK   P3PU

#endif

